package com.xiangxiao.rpan.data.enums;

import java.util.Arrays;
import java.util.Objects;

/**
 * @auther xiangxiao
 * @email 573768011@qq.com
 * @data 2024/7/8 10:29
 */
public enum StatusEnum {

  FINISHED(1, "finished"),
  FAILED(0, "failed"),
  ;

  private final Integer code;
  private final String desc;

  StatusEnum(Integer code, String desc) {
    this.desc = desc;
    this.code = code;
  }

  public static StatusEnum getByCode(Integer code) {
    if (code == null) {
      return null;
    }
    return Arrays.stream(StatusEnum.values())
        .filter(a -> Objects.equals(a.getCode(), code))
        .findFirst().orElse(null);
  }

  public String getDesc() {
    return desc;
  }

  public Integer getCode() {
    return code;
  }
}
